<template>
  <el-container>
    <!-- 欢迎信息 -->
    <div class="welcome-text">
      欢迎您，{{ currentUserName }}
    </div>
    <el-main>
      <!-- 四宫格容器 -->
      <div class="icon-grid">
        <router-link to="/member" class="icon-item">
          <i class="el-icon-user"></i>
          <p>会 员</p>
        </router-link>
        <router-link to="/classtable" class="icon-item">
          <i class="el-icon-date"></i>
          <p>课 程 表</p>
        </router-link>
        <router-link to="/preorder" class="icon-item">
          <i class="el-icon-phone-outline"></i>
          <p>预 约</p>
        </router-link>
        <router-link to="/equipment" class="icon-item">
          <i class="el-icon-collection-tag"></i>
          <p>设 备</p>
        </router-link>
      </div>
      <!-- AI助手按钮 -->
      <div class="ai-helper-btn" @click="toggleKimiAI">
        <i class="el-icon-chat-line-round"></i> 我是KIMI助手，有什么关于健康的问题都可以来问我哦！
      </div>
      <!-- Kimi AI显示区域 -->
      <div v-if="showKimiAI" class="kimi-ai">
        <iframe src="https://kimi.moonshot.cn/" frameborder="0" width="100%" height="600px"></iframe>
      </div>
      <!-- 操作按钮区域 -->
      <div class="operation-btns">
        <!-- 退出登录按钮 -->
        <div class="logout-btn" @click="logout">
          <i class="el-icon-switch-button"></i> 退出登录
        </div>
        <!-- 数据报表按钮，根据用户身份决定是否显示 -->
        <div v-if="userIdentity === 'ad'" class="report-btn" @click="goToReport">
          <i class="el-icon-s-data"></i> 数据报表
        </div>
      </div>
    </el-main>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      showKimiAI: false, // 控制Kimi AI显示的数据属性
      userIdentity: '',
      currentUserName: '', // 当前用户名
    };
  },
  mounted() {
    this.userIdentity = localStorage.getItem('userIdentity');
    this.currentUserName = localStorage.getItem('currentUserName'); // 从localStorage获取用户名
    console.log('当前用户身份：', this.userIdentity);
    console.log('当前用户名：', this.currentUserName);
  },
  methods: {
    toggleKimiAI() {
      this.showKimiAI = !this.showKimiAI; // 切换Kimi AI的显示状态
    },
    logout() {
      // 清除本地存储中的用户信息
      localStorage.removeItem('currentUserName');
      localStorage.removeItem('userIdentity');
      this.$router.push('/'); // 跳转到首页
    },
    goToReport() {
      this.$router.push('/report'); // 跳转到数据报表页面
    }
  },
};
</script>

<style scoped>
.el-main {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 0;
  height: 846px;
  background-image: url(../assets/img/home.jpg) !important;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.icon-grid {
  width: 65%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-gap: 20px;
  margin-left: 4%;
  margin-top: 2%;
  margin-bottom: 2%;
}

.icon-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  color: inherit;
  text-decoration: none;
  border: 2px;
  border-radius: 10px;
  padding: 10px;
  margin: 10px;
  transition: transform 0.2s;
  background-color: white;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.icon-item:hover {
  cursor: pointer;
  transform: scale(1.05);
}

.icon-item i {
  font-size: 12rem;
}

.icon-item p {
  font-size: 1.1rem;
  margin-top: 0.3rem;
}

.ai-helper-btn {
  position: absolute;
  bottom: 20px;
  left: 20px;
  cursor: pointer;
  padding: 10px;
  border-radius: 50%;
  background-color: #409eff;
  color: white;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  transition: background-color 0.3s ease;
}

.ai-helper-btn:hover {
  background-color: #66b1ff;
}

.kimi-ai {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: white;
  border: 1px solid #ccc;
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  z-index: 1000;
  width: 80%;
  max-width: 1200px;
}

iframe {
  width: 100%;
  height: 600px;
}

.operation-btns {
  position: absolute;
  top: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px; /* 按钮之间的间距 */
}

.logout-btn, .report-btn {
  cursor: pointer;
  padding: 10px;
  border-radius: 5px;
  background-color: #f56c6c;
  color: white;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  transition: background-color 0.3s ease;
}

.logout-btn:hover, .report-btn:hover {
  background-color: #e45656;
}

/* 新增欢迎信息样式 */
.welcome-text {
  position: absolute;
  top: 20px;
  left: 20px;
  color: white;
  font-weight: bold;
  font-size: 1.2rem;
}
</style>